//
//  ViewController.m
//  中石化便利店
//
//  Created by ggx on 2017/3/7.
//  Copyright © 2017年 高广校. All rights reserved.
//

#import "HomeViewController.h"
#import "OrderDetailViewController.h"
#import "BLHomeBannerModel.h"
#import "HomeCell.h"
@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"首页";
           
    [self.view addSubview:self.baseTable];
    self.baseTable.rowHeight = 160*Device_Ccale;
    [self.baseTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self.baseTable.mj_header beginRefreshing];
    
}
-(void)refreshView{
    
    [self showAnimated:NO title:@"加载轮播图" whileExecutingBlock:^CGDataResult *{
        return [Service loadNetWorkingByParameters:@{} andBymethodName:@"v1/sowingmap"];
    } completionBlock:^(BOOL b, CGDataResult *r) {
        if (b) {
            NSArray *bannerArr = [BLHomeBannerModel mj_objectArrayWithKeyValuesArray:r.dataList];
            
            self.dataArray = bannerArr;
            [self.baseTable reloadData];
            [self.baseTable.mj_header endRefreshing];
        }
    }];
    
   
}

-(void)loadMore{
    [self.baseTable.mj_footer endRefreshing];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellidenti = @"HomeCell";
    HomeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidenti];
    if (!cell) {
        cell = [[HomeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidenti];
    }
    cell.homeEntity = self.dataArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderDetailViewController *Vc = CreateViewController(@"OrderDetailViewController");
//    Vc.orderId = [[(HomeCell *)[tableView cellForRowAtIndexPath:indexPath] homeOrderEntity]orderId];
    PushViewController(Vc);
}

-(BOOL)hidesBottomBarWhenPushed{
    return NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
